package com.wcl.nullmusic.ui.service;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

import com.wcl.nullmusic.R;
import com.wcl.nullmusic.ui.activity.MainActivity;

/**
 * Created by dllo on 16/1/22.
 */
public class JpushReceiver extends BroadcastReceiver {
    private NotificationManager manager;

    @Override
    public void onReceive(Context context, Intent intent) {
        showNotification(context);
    }

    private void showNotification(Context context) {
        manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification.Builder builder = new Notification.Builder(context);
        builder.setAutoCancel(true); // 操作后该通知消失
        builder.setTicker("NullMusic");
        builder.setSmallIcon(R.mipmap.null_64); //通知的图标
        builder.setContentTitle("音乐来袭"); // 通知标题
        builder.setContentText("又有好音乐来啦!!!!亲"); // 通知内容
        builder.setWhen(System.currentTimeMillis());

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_ONE_SHOT);
        builder.setContentIntent(pendingIntent);
        Notification notification = builder.build();
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        manager.notify(5, notification);
    }
}
